<template>
  <div>
    <div class="box">
      <p>姓名：{{ user1 }}</p>
      <p>年龄：{{ init }}</p>
      <p>兄弟组件之间传输数据 ---> 数据接收</p>
      <hr>
      <!-- <button >接收数据</button> -->
      <p>收到了Right模块的数据: {{ MyfromStr }}</p>
    </div>
  </div>
</template>

<script>
// 导入 eventBus 模块
import bus from "@/components/EventBus.js"
export default {
  props: {
    init: {
      default: "null",
    },
    user: {
      default: "null",
    },
  },
  data() {
    return {
      user1: this.user,
      age: this.init,
      MyfromStr: ''
    };
  },
  created(){
      // 为 Bus 绑定自定义事件
      bus.$on('share', (val)=>{
        //   console.log(val)
        this.MyfromStr = val
      })
  },
};
</script>

<style lang="less" scoped>
.box{
    height: 200px;
    color: white;
    background-color: red;
}
</style>